package ext.tianma.part.processors;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.List;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.DefaultObjectFormProcessor;
import com.ptc.core.components.forms.FormProcessingStatus;
import com.ptc.core.components.forms.FormResult;
import com.ptc.core.components.util.FeedbackMessage;
import com.ptc.core.ui.resources.FeedbackType;
import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.com.core.CoreUtil;
import ext.com.iba.IBAUtil;
import ext.tianma.part.PartWorkflowUtil;
import ext.tianma.part.Interface.MDMInterface.Service.PartInformationService;
import ext.tianma.workflow.SubmitBomReview;
import wt.fc.QueryResult;
import wt.fc.collections.WTArrayList;
import wt.method.RemoteAccess;
import wt.part.WTPart;
import wt.util.WTException;
import wt.workflow.engine.WfEngineHelper;
import wt.workflow.engine.WfProcess;
import wt.workflow.engine.WfState;
/**
 * 由于手动发布物料到MDM
 * @author laichao_sun
 *
 */
public class MDMsubmission extends DefaultObjectFormProcessor implements RemoteAccess, Serializable
{
	@Override
	public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> arg1) throws WTException {
		FormResult formresult = new FormResult();
		//formresult.setStatus(FormProcessingStatus.SUCCESS);
	
		NmOid nmoid = arg0.getActionOid();
		WTPart currentPart = (WTPart) nmoid.getRefObject();	
	

		if( currentPart != null ){
			//获取Design视图的部件
			WTPart part = CoreUtil.getWTPartByNumberAndView(currentPart.getNumber(), "Design");// 获取design试图
			//获取非Design视图的部件
			WTArrayList erpObjs = ext.tianma.part.PartWorkflowUtil.getAllPartViews(part);
			
			try {
				boolean flag=PartInformationService.sendPartsService(part,erpObjs,"1");
				if(flag) {
					FeedbackMessage feedbackmessage = new FeedbackMessage(
							FeedbackType.SUCCESS, null, "手动发布到MDM", null, "成功");
					formresult.addFeedbackMessage(feedbackmessage);
					return formresult;
				}else {
					FeedbackMessage feedbackmessage = new FeedbackMessage(
							FeedbackType.FAILURE, null, "手动发布到MDM", null, "失败");
					formresult.addFeedbackMessage(feedbackmessage);
					return formresult;
				}
			} catch (Exception e) {
				FeedbackMessage feedbackmessage = new FeedbackMessage(
						FeedbackType.FAILURE, null, "手动发布到MDM", null, "失败");
				formresult.addFeedbackMessage(feedbackmessage);
				e.printStackTrace();
				return formresult;
			}	
		}
		return formresult;

	}
}
